/**
 * @(#)ShowItemController.java, 2010-5-15. 
 *
 */
package com.rsstuan.web.controller;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;

import com.rsstuan.storage.data.TuanGouItemData;
import com.rsstuan.storage.impl.JDOTuanGouItemStorage;

/**
 *
 * @author guosq
 *
 */
public class ShowItemController extends SpringController {
    
    public ModelAndView show(HttpServletRequest request,
            HttpServletResponse response) throws IOException {

        response.setContentType("text/html;charset=utf-8");
        response.setStatus(HttpServletResponse.SC_OK);
        JDOTuanGouItemStorage storage = new JDOTuanGouItemStorage();
        List<TuanGouItemData> items = storage.getItems();
        response.getWriter().println("<html>");
        response.getWriter().println(" <head></head>");
        response.getWriter().println(" <body>");
        
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
        if (items != null) {
             for (TuanGouItemData item : items) {
                 response.getWriter().println( item.getTitle() + "<br/>");
                 response.getWriter().println("链接 = <a href=\"" + item.getLink() + "\">" + item.getLink() + "</a>" + "<br/>");
                 response.getWriter().println("<img src=\"" + item.getImage() + "\" /><br/>");
                 response.getWriter().println("价格 = " + item.getPrice() + "<br/>");
                 response.getWriter().println("原价 = " + item.getOrigPrice() + "<br/>");
                 response.getWriter().println("地址 = " + item.getAddress() + "<br/>");
                 response.getWriter().println("结束时间 = " + sdf.format(new Date(item.getEndTime())) + "<br/>");
                 response.getWriter().println("购买人数 = " + item.getOrderNum() + "<br/>");
                 response.getWriter().println("----------------------------<br/>");
                 
                 
             }
        }
        return null;
    }      

}
